home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <sys/stat.h>
- #include "../paths.h"
- #include "../misc/misc.h"
- #include "userconf.h"
-
- static char **tb;
- static int nb;
-
- static void shells_read ()
- {
- if (tb == NULL){
- /* #Specification: userconf / /etc/shells & getusershell()
- Shells available to configure user accounts are defined
- by getusershell() (which reads /etc/shells optionnally).
-
- It is assumed that the first entry in /etc/shells is the default
- shell (When the field is empty in /etc/passwd).
- */
- tb = (char**)malloc_err(100*sizeof(char*));
- char *pt;
- while ((pt=getusershell())!=NULL){
- tb[nb++] = strdup(pt);
- }
- }
- }
-
- /*
- Return != 0 if a path is an accepted shell
- */
- int shells_isok(const char *path)
- {
- shells_read();
- int ret = 0;
- if (path[0] == '\0'){
- ret = 1;
- }else{
- for (int i=0; i<nb; i++){
- if (strcmp(tb[i],path)==0){
- ret = 1;
- break;
- }
- }
- }
- return ret;
- }
-
- int shells_exist (const char *path)
- {
- struct stat sstat;
- int ret = 0;
- if (path[0] == '\0'){
- ret = 1;
- }else{
- if (stat(path,&sstat)!=-1
- && S_ISREG(sstat.st_mode)
- && sstat.st_mode & 1){
- ret = 1;
- }
- }
- return ret;
- }
-
- /*
- Return the path of the default shell for normal user.
- */
- const char *shells_getdefault()
- {
- shells_read();
- return tb[0];
- }
-
-